package com.ruoyi.web.controller.user;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.user.domain.UserCert;
import com.ruoyi.user.service.UserCertService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 实名认证记录Controller
 *
 * @author ruoyi
 * @date 2024-01-10
 */
@RestController
@RequestMapping("/user/cert")
public class UserCertController extends BaseController {
    @Autowired
    private UserCertService userCertService;

    /**
     * 查询实名认证记录列表
     */
    @PreAuthorize("@ss.hasPermi('user:cert:list')")
    @PostMapping("/list")
    public TableDataInfo list(UserCert userCert) {
        startPage();
        List<UserCert> list = userCertService.selectUserCertList(userCert);
        return getDataTable(list);
    }

    /**
     * 导出实名认证记录列表
     */
    @PreAuthorize("@ss.hasPermi('user:cert:export')")
    @Log(title = "实名认证记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserCert userCert) {
        List<UserCert> list = userCertService.selectUserCertList(userCert);
        ExcelUtil<UserCert> util = new ExcelUtil<>(UserCert.class);
        util.exportExcel(response, list, "实名认证记录数据");
    }

    /**
     * 获取实名认证记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('user:cert:query')")
    @PostMapping(value = "getInfo/{certId}")
    public AjaxResult getInfo(@PathVariable("certId") Long certId) {
        return success(userCertService.selectUserCertByCertId(certId));
    }

    /**
     * 审核实名认证记录
     */
    @PreAuthorize("@ss.hasPermi('user:cert:examine')")
    @Log(title = "审核实名认证记录", businessType = BusinessType.INSERT)
    @PostMapping("examine")
    public AjaxResult examine(@RequestBody UserCert userCert) {
        return toAjax(userCertService.examine(userCert));
    }

    /**
     * 批量删除实名认证记录
     */
    @PreAuthorize("@ss.hasPermi('user:cert:remove')")
    @Log(title = "会员级别", businessType = BusinessType.DELETE)
    @PostMapping("/remove/{certIds}")
    public AjaxResult remove(@PathVariable Long[] certIds) {
        return toAjax(userCertService.deleteUserCertByCertIds(certIds));
    }
}
